<?php
namespace App\Admin\Controllers\Consultation;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Encore\Admin\Layout\Content;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;
use App\Admin\Controllers\Common\Common;

class DashboardController extends Controller {
	public function index(Content $content) {
		return Admin::content(function (Content $content) {
			$numbers = [
				"phone_ask" => [123456,12345],
				"appointment" => [1234,1234,1234,1234],
				"enroll" => [1234,1234],
				"second_enroll" => [1234,1234,1234,1234],
				"distribute" => [1234,1234],
				"p_meeting" => [1234,1234,1234],
			];
            $content->header("咨询部");
            $content->description("Dashboard");
			$content->body(view("admin.consultation.dashboard.index",[
				"Numbers" => $numbers
			]));
        });
	}

	public function clearExcel() {
		try {
			$path = public_path()."/excel/";
			if(is_dir($path)){
				$this->deleteDir($path);
			}
			return ['code'=>1,'msg'=>"清理成功"];
		} catch (\Exception $e) {
			return ['code'=>0,'msg'=>"清理失败:".$e->getMessage()];
		}
	}
	private function deleteDir($path) {
		$arr = scandir($path);
		unset($arr[0]);
		unset($arr[1]);
		foreach($arr as $v){
			if(is_dir($path.$v)){
				$this->deleteDir($path.$v.'/');
				rmdir($path.$v);
			}else{
				unlink($path.$v);
			}
		}
	}
}
